﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevTeam;
using System;

namespace ConfExpert.Forms.Depo.Kargo
{
    public partial class KargoMasrafByMusteri : XForm
    {
        public KargoMasrafByMusteri()
        {
            InitializeComponent();
        }

        private void KargoMasrafByMusteri_Load(object sender, EventArgs e)
        {
            Rfrsh();

            splitContainerControl1.AutoSize();

            ((RepositoryItemComboBox)cmbYil.Edit).Items.AddRange(new object[] { 2015, 2016 });
            ((RepositoryItemComboBox)cmbYil.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            cmbYil.EditValueChanged += cmbYil_EditValueChanged;
            cmbYil.EditValue = DateTime.Now.Year;
        }

        private void Rfrsh()
        {
            gridView1.Init("GetKargoMasrafByMusteri", cmbYil.EditValue.ToInt());
            gridView1.AddDetailGrid(gridView2, "CariId");
            gridView1.FormatAsNumber(1, "ToplamKargo", "FaturalanacakKargoTutar", "FaturalanacakMalzemeTutar");
            gridView1.AddSummary("ToplamKargo", "FaturalanacakKargoTutar", "FaturalanacakMalzemeTutar");

            gridView2.FormatAsNumber(1, "ToplamKargo", "FaturalanacakKargoTutar", "FaturalanacakMalzemeTutar");
            gridView2.AddSummary("ToplamKargo", "FaturalanacakKargoTutar", "FaturalanacakMalzemeTutar");
            gridView1.FocusedRowChanged -= gridView1_FocusedRowChanged;
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }

        void cmbYil_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }
    }
}
